home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 862 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: Rich Paul <rpaul@trcinc.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: A couple of questions about strings
  5. Date: 26 Mar 1996 10:58:31 PST
  6. Organization: Technical Resource Connection
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <31580FC6.1A61@trcinc.com>
  9. References: <1278@dawes.win.net>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Tue, 26 Mar 1996 10:39:50 -0500
  12. X-Mailer: Mozilla 2.0 (WinNT; I)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMVg+1Uy4NqrwXLNJAQHObwIAjeTlyFTWYhG3qlEc+/LEQKTgU2aK6dFf
  15.     ZDsJKlz5cUmdI0DdPp4g/Q2WG2gTxAWReUJZE84FBolUyrgwadcU3A==
  16.     =r72p
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. Beman Dawes wrote:
  20. > >a) Why does basic_string::copy() not also copy an ending '\0'? If
  21. > >there's some sort of good reason, why wasn't a function added that did
  22. > >this (perhaps basic_string::copy_null() or something)? I must say, it
  23. > >is very inconvenient to copy a string to a C-style array of chars with
  24. > >the current string class.
  25. > There is such a function - it is called c_str().
  26.  
  27. well, to be equivilent, it would really be:
  28.  
  29. strncpy ( buffer, string::c_str(), x );
  30. buffer[x] = 0;    // only if strlen(buffer > x), but it's not safe
  31.         // to check that way, since strlening a non-termed                         
  32.         // char[] is a bad thing
  33. ---
  34. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  35.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  36.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  37.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  38.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  39. ]
  40.